#include "test.h"



namespace ns_MemoryPointerTest
{
	const Int32 COUNT = 10;

	void testMemoryPointer()
	{
		std::cout << "test MemoryPointer" << std::endl;

		MemoryPointer<Int32> pointer;
		pointer.CheckSetLength(COUNT);
		Int32* ptr = pointer.DataPtr();

		for (int i = 0; i < pointer.Length; i++)
		{
			ptr[i] = i;
		}

		Span<Int32> span = pointer.GetSpan();
		//span.Length = 5;
		//span.DataPtr = nullptr;

		for (int i = 0; i < span.Length; i++)
		{
			std::cout << span.DataPtr[i] << std::endl;
		}

		std::cout << "\r\ntest pointer.fill(20)" << std::endl;
		pointer.Fill(20);
		for (int i = 0; i < span.Length; i++)
		{
			std::cout << span.DataPtr[i] << std::endl;
		}

		std::cout << "\r\ntest pointer.Clear()" << std::endl;
		pointer.Clear();
		for (int i = 0; i < span.Length; i++)
		{
			std::cout << span.DataPtr[i] << std::endl;
		}
	}

	void testIQMemoryPointer()
	{
		std::cout << "\r\ntest IQMemoryPointer" << std::endl;
		IQMemoryPointer<Int32> pointer;
		pointer.CheckSetLength(COUNT);

		Int32* iData = pointer.IDataPtr();
		Int32* qData = pointer.QDataPtr();
		for (int i = 0; i < COUNT; i++)
		{
			iData[i] = 10 + i;
			qData[i] = 100 + i;
		}

		IQSpan<Int32> iqSpan= pointer.GetSpan(COUNT);
		//iqSpan.Length = 5;

		for (int i = 0; i < iqSpan.Length; i++)
		{
			std::cout << "I:" << iqSpan.IDataPtr[i] << "  q:" << iqSpan.QDataPtr[i] << std::endl;
		}

		std::cout << "\r\ntest pointer.fill(20)" << std::endl;
		pointer.Fill(20);
		for (int i = 0; i < iqSpan.Length; i++)
		{
			std::cout << "I:" << iqSpan.IDataPtr[i] << "  q:" << iqSpan.QDataPtr[i] << std::endl;
		}

		std::cout << "\r\ntest pointer.Clear()" << std::endl;
		pointer.Clear();
		for (int i = 0; i < iqSpan.Length; i++)
		{
			std::cout << "I:" << iqSpan.IDataPtr[i] << "  q:" << iqSpan.QDataPtr[i] << std::endl;
		}
	}
}


void MemoryPointerTest::test()
{
	ns_MemoryPointerTest::testMemoryPointer();
	ns_MemoryPointerTest::testIQMemoryPointer();

}


